package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.ProductsDao;
import com.example.wujinapi.dao.ProductspecificationDao;
import com.example.wujinapi.entity.Products;
import com.example.wujinapi.entity.Productspecification;
import com.example.wujinapi.service.ProductspecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Productspecification)表服务实现类
 *
 * @author makejava
 * @since 2023-07-31 23:01:46
 */
@Service("productspecificationService")
public class ProductspecificationServiceImpl extends ServiceImpl<ProductspecificationDao, Productspecification> implements ProductspecificationService {

    @Autowired
    private ProductspecificationDao productspecificationDao;

    @Override
    public void addProductspecification(Productspecification productspecification) {
        Productspecification spData=productspecificationDao.selectOne(new QueryWrapper<Productspecification>().eq("spname", productspecification.getSpname()));
        if(spData==null){ //为空才插入新用户
            productspecificationDao.insert(productspecification);
        }
    }

    @Override
    public void updateProductspecification(Productspecification productspecification) {
        Productspecification spData=productspecificationDao.selectOne(new QueryWrapper<Productspecification>().eq("id", productspecification.getId()));
        if(spData!=null){
            productspecification.setId(spData.getId());
            productspecificationDao.updateById(productspecification);
        }
    }

    @Override
    public void deleteProductspecification(int spId) {
        productspecificationDao.delete(new QueryWrapper<Productspecification>().eq("id",spId));
    }

    @Override
    public Productspecification getProductspecificationByspId(int spId) {
        Productspecification spdata=productspecificationDao.selectOne(new QueryWrapper<Productspecification>().eq("id", spId).eq("isshow",1)); //1显示 0不显示
        return spdata!=null?spdata:null;
    }

    @Override
    public List<Productspecification> getProductspecificationsByProductID(int ProductId) {
        List<Productspecification> spListData=productspecificationDao.selectList(new QueryWrapper<Productspecification>().eq("mainpid", ProductId).eq("isshow",1)); //1显示 0不显示
        return spListData!=null?spListData:null;
    }
}

